package com.tanhua.server.controller;

import cn.hutool.core.util.ObjectUtil;
import com.tanhua.server.service.BaiduService;
import com.tanhua.server.vo.HuanXinUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/baidu")
public class BaiduController {

    @Autowired
    private BaiduService baiduService;

    @PostMapping("/location")
    public ResponseEntity<Void> updateLocation(@RequestBody Map<String, Object> param){
        try {
            Double latitude = Double.valueOf(param.get("latitude").toString()) ;
            Double longitude = Double.valueOf(param.get("longitude").toString());
            String address = param.get("addrStr").toString();
            this.baiduService.updateLocation(latitude, longitude, address);
            return ResponseEntity.ok(null);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

}
